from functools import reduce


class CfzTest:
    __slots__ = ['age', 'name', '_sex', '__mimi']  # 使用__slots__属性来指定对象的共有属性来防止内存过渡消耗
    # age = None
    # name = None

    # 私有变量前带__
    # __mimi = None

    # 保护变量前带_
    # _sex = None

    def __init__(self):
        self.age = 10
        self.name = "陈峰展"
        self._sex = "男"
        self.__mimi = "我有一个秘密"

    def print_name(self):
        print("我的名字是{}".format(self.name))


class CfzBigClass(CfzTest):

    def print_big_name(self):
        print("我的名字是{name}，我的年龄是{age}，我的性别是{sex}".format(name=self.name, age=self.age, sex=self._sex))


class LypTest:
    day = None

    def __init__(self):
        self.day = 28


class CfzBigBigClass(LypTest, CfzBigClass):

    def __init__(self):
        LypTest.__init__(self)
        CfzBigClass.__init__(self)

    def print_so_big_name(self):
        print("Python支持多继承" + self.name)
        print("Python支持多继承" + str(self.day))

    @classmethod
    def test_adds(cls, val1, *vals):
        """
        DOC标准注释
        :param cls: 
        :param val1: 要相加的参数1
        :param vals: 要相加的其他参数
        :return: 返回相加后的总和
        """
        print(cls)
        val_toal = val1
        for val in vals:
            val_toal += val
        return val_toal

    @staticmethod
    def test_kvargs(**kwargs):
        """
        测试不定长键值对参数
        :param kwargs: 
        :return: 
        """
        for key, val in kwargs.items():
            print("{0}:{1}".format(key, val))

    @staticmethod
    def test_args_kwargs(farg1, farg2, *args, **kwargs):
        """
        测试*args, **kwargs一起使用的情况，注意顺序必须是：必要参数1, 必要参数2, 必要参数..., *args, **kwargs
        :param farg1: 必要参数1
        :param farg2: 必要参数2
        :param args: 可选其他参数
        :param kwargs: 可选不定长键值对参数
        :return: 
        """
        print("必要参数1:" + farg1)
        print("必要参数2:" + farg2)
        print("可选其他参数")
        for arg in args:
            print(arg)
        print("可选不定长键值对参数")
        for key, val in kwargs.items():
            print("{0}:{1}".format(key, val))

    def __iter__(self):
        """
        自定义迭代方法
        :return: 
        """
        pass

    def __getitem__(self, item):
        """
        自定义键值对迭代方法
        :param item: 
        :return: 
        """
        pass

    def __next__(self):
        """
        实现迭代器
        Python2中的实现方法为next，在Python3中替代为魔法方法__next__
        :return: 
        """
        pass

    @staticmethod
    def test_generator():
        """
        测试由yield关键字的生成器
        :return: 
        """
        for i in range(10):
            yield i

    @staticmethod
    def test_map():
        """
        测试map函数
        :return: 
        """
        items = [1, 2, 3, 4, 5, 6]
        outs = map(lambda x: x * 2, items)
        return outs

    @staticmethod
    def test_filter():
        """
         测试filter函数
        :return: 
        """
        items = [1, 2, 3, 4, 5, 6]
        outs = filter(lambda x: x > 3, items)
        return outs

    @staticmethod
    def test_reduce():
        """
        测试使用functools中的reduce方法来进行列表的汇总操作
        :return: 
        """
        items = [1, 2, 3, 4, 5, 6]
        out = reduce(lambda x, y: x + y, items)
        return out
